# 登录
import requests
import config


class FutureLogin:
    def __init__(self):
        self.verify_code_url = config.BASE_URL + "/api/verify-code/get-code"
        self.verify_value_url = config.BASE_URL + "/api/verify-code/get-verify-code"
        self.login_url = config.BASE_URL + "/api/user/login"

    # 获取验证码的信息：id和imgPath
    def getCaptcha(self):
        return requests.get(url=self.verify_code_url)

    # 获取验证码的值：captchaValue
    def getCaptchaValue(self, verifyid):
        return requests.get(url=self.verify_value_url, params=verifyid)

    # 登录
    def login(self, json_data):
        return requests.post(url=self.login_url, json=json_data)

    # 获取验证码信息
    def getCaptchaAllIm(self):
        # 获取验证码的信息：id和imgPath
        captcha_response = self.getCaptcha()
        captcha_id = captcha_response.json()["data"]["id"]
        captcha_img = captcha_response.json()["data"]["imgPath"]
        # 获取验证码的值：captchaValue
        verifyid = {"id": captcha_id}
        value_response = self.getCaptchaValue(verifyid)
        captcha_value = value_response.json()["msg"]
        return {
            "captchaId": captcha_id,
            "captcha": captcha_value,
            "imgPath": captcha_img
        }
